package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.SysOwnerCars;
import com.ruoyi.system.service.ISysOwnerCarsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysCarsMapper;
import com.ruoyi.system.domain.SysCars;
import com.ruoyi.system.service.ISysCarsService;

/**
 * 车辆信息表Service业务层处理
 *
 * @author ruoyi
 * @date 2022-05-11
 */
@Service
public class SysCarsServiceImpl implements ISysCarsService {
    @Autowired
    private SysCarsMapper sysCarsMapper;

    @Autowired
    private ISysOwnerCarsService sysOwnerCarsService;

    /**
     * 查询车辆信息表
     *
     * @param carId 车辆信息表主键
     * @return 车辆信息表
     */
    @Override
    public SysCars selectSysCarsByCarId(Long carId) {
        return sysCarsMapper.selectSysCarsByCarId(carId);
    }

    /**
     * 查询车辆信息表列表
     *
     * @param sysCars 车辆信息表
     * @return 车辆信息表
     */
    @Override
    public List<SysCars> selectSysCarsList(SysCars sysCars) {
        return sysCarsMapper.selectSysCarsList(sysCars);
    }

    @Override
    public List<SysCars> selectSysCarsListByIds(Long[] ids) {
        return sysCarsMapper.selectSysCarsListByIds(ids);
    }

    /**
     * 新增车辆信息表
     *
     * @param sysCars 车辆信息表
     * @return 结果
     */
    @Override
    public int insertSysCars(SysCars sysCars, Long userId) {
        sysCarsMapper.insertSysCars(sysCars);
        SysCars sysCar = sysCarsMapper.selectSysCarsList(sysCars).get(0);
        SysOwnerCars sysOwnerCars = new SysOwnerCars();
        sysOwnerCars.setOwnerId(userId);
        sysOwnerCars.setCarId(sysCar.getCarId());
        return sysOwnerCarsService.insertSysOwnerCars(sysOwnerCars);
    }

    /**
     * 修改车辆信息表
     *
     * @param sysCars 车辆信息表
     * @return 结果
     */
    @Override
    public int updateSysCars(SysCars sysCars) {
        return sysCarsMapper.updateSysCars(sysCars);
    }

    /**
     * 批量删除车辆信息表
     *
     * @param carIds 需要删除的车辆信息表主键
     * @return 结果
     */
    @Override
    public int deleteSysCarsByCarIds(Long[] carIds) {
        return sysCarsMapper.deleteSysCarsByCarIds(carIds);
    }

    /**
     * 删除车辆信息表信息
     *
     * @param carId 车辆信息表主键
     * @return 结果
     */
    @Override
    public int deleteSysCarsByCarId(Long carId) {
        return sysCarsMapper.deleteSysCarsByCarId(carId);
    }
}
